// 请求得封装头部
// {
// 	/* <script type="text/javascript" src="js/jquery.cookie.js"></script> */
// }
var commomUrl = "https://portal-api.jfzh.com.cn/JFZH-Portal/app"; // 公共前缀url
// var commomUrl = "http://192.168.124.6:8050/JFZH-Portal/app"; // 公共前缀url
var phoneCodeUrl = "https://portal-api.jfzh.com.cn/JFZH-Portal/jfGuanWang"; // 手机验证码以及登录前缀url
// var phoneCodeUrl = "http://192.168.124.6:8050/JFZH-Portal/jfGuanWang"; // 手机验证码以及登录前缀url
//给header添加token
var info = JSON.parse(localStorage.getItem("userInfo"));
var token
if (info) {
	token = info.token
} else {
	token = ''
}
var commonHeader = { // 公共header
	"Content-Type": "application/json",
	"Authorization": "Bear " + "...",
	"token": token
}
// var script = document.createElement('script')
// script.type = 'text/javascript'
// script.src = './jquery.cookie.js'
// document.head.appendChild(script)
// document.write("<script language=javascript src='./jquery.cookie.js’></script>");
//封装出去一个公共路径
function baseUrl() {
	return commomUrl
}

function baseUrl1() {
	return 'https://rhtm.jfzh.com.cn/'
}
//公共ajax封装
function ajax(url, type, params, successfn, errorfn) {
	$.ajax({
		url: commomUrl + url,
		type: type,
		headers: commonHeader,
		data: params,
		success: function (res) {

			if (res.code != 200) {
				let sendMsg = ''
				if (res.msg) {
					sendMsg = res.msg
				} else {
					sendMsg = res.message
				}
				showMessage(sendMsg, 0);
			} else {
				successfn(res)
			}
		},
		error: function (res) {
			// errorfn(res);
			console.log(url)
		},
		complete: function () {
			// console.log('结束 看需要写不写');
		}
	});

}
//二手房列表接口
function houseListAjax(url, type, params, successfn, errorfn) {
	$.ajax({
		url: commomUrl + url,
		type: type,
		headers: commonHeader,
		data: params,
		success: function (res) {

			if (res.code != 200) {
				let sendMsg = ''
				if (res.msg) {
					sendMsg = res.msg
				} else {
					sendMsg = res.message
				}
				showMessage(sendMsg, 0);
			} else {
				successfn(res)
			}
		},
		error: function (res) {
			// errorfn(res);
			console.log(url)
		},
		complete: function () {
			// console.log('结束 看需要写不写');
		}
	});

}
//公共ajax封装
function phoneAjax(url, type, params, successfn, errorfn) {
	$.ajax({
		url: phoneCodeUrl + url,
		type: type,
		headers: commonHeader,
		data: params,
		success: function (res) {
			if (res.code != 200) {
				let sendMsg = ''
				if (res.msg) {
					sendMsg = res.msg
				} else {
					sendMsg = res.message
				}
				showMessage(sendMsg, 0);
			} else {
				successfn(res)
			}
		},
		error: function (res) {
			// errorfn(res);
			console.log(res)
		},
		complete: function () {
			// console.log('结束 看需要写不写');
		}
	});

}


//消息提示
function showMessage(message, type) {
	let messageJQ = $("<div class='showMessage'>" + message + "</div>");
	if (type == 0) {
		messageJQ.addClass("showMessageError");
	} else if (type == 1) {
		messageJQ.addClass("showMessageSuccess");
	}
	/**先将原始隐藏，然后添加到页面，最后以600秒的速度下拉显示出来*/
	messageJQ.hide().appendTo("body").slideDown(600);
	/**3秒之后自动删除生成的元素*/
	window.setTimeout(function () {
		messageJQ.remove();
	}, 2000);
}